<html class="standard"><head>
        <meta charset="utf-8">
        <title>管理员</title>
        <link href="../css/im_index/ly/c.css" type="text/css" rel="stylesheet">
        <link href="../css/im_index/ly/main.css" type="text/css" rel="stylesheet">
        <link href="../css/framework/layui.css" type="text/css" rel="stylesheet">
        <link href="../css/im_index/shopkeeper.css" type="text/css" rel="stylesheet">
        <!-- <link href="../css/framework/bootstrap-theme.css" type="text/css" rel="stylesheet"> -->

    </head>
    <body>

        <div id="wrap">
            <div id="header">
                <div class="top">
                        
                    <ul class="layui-nav">
                        <div id="top" class="top-in">

                                    
                            <li class="layui-nav-item home" >
                                    <a href="../html/admin.html" class="active"  style="color:#22d7c6">首页</a>
                            </li>

                            <li class="layui-nav-item">
                                    <a href="" class="active">管理员</a>
                            </li>


                            <li class="layui-nav-item">
                                    <a href="" class="active" onclick="logout()">退出</a>
                            </li>
                                    
                    </ul>

                   

                </div>
                </div> 
                
                <div id="service-list">
                    <div id="info">
                        <span style="height:2px">增加新账号</span>
                        <hr class="layui-bg-green">
                        <br>
                        <br>
                        <div class="layui-form" action="">
                            <div class="layui-form-item">
                                    <label class="layui-form-label">昵称</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="title" required lay-verify="required" placeholder="请输入昵称"
                                            autocomplete="off" class="layui-input" v-model="nickname">
                                    </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">账号</label>
                                <div class="layui-input-block">
                                    <input type="text" name="title" required lay-verify="required" placeholder="请输入账号"
                                        autocomplete="off" class="layui-input" v-model="account">
                                </div>
                            </div>
        
                            <div class="layui-form-item">
                                <label class="layui-form-label">密码</label>
                                <div class="layui-input-block">
                                    <input type="text" name="title" required lay-verify="required" placeholder="请输入手机号码"
                                        autocomplete="off" class="layui-input" v-model="password">
                                </div>
                            </div>
        
                            <div class="layui-form-item">
                                <label class="layui-form-label">角色</label>
                                <div class="layui-input-block">
                                    <input type="text" name="title" required lay-verify="required" placeholder="请输入角色  0是用户  1是客服  2是店主"
                                        autocomplete="off" class="layui-input" v-model="role">
                                </div>
                            </div>
        
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="formDemo" @click="register()" >立即提交</button>
                                </div>
                            </div>

                            <label>{{tip}}</label>

                        </div>
                        
                    </div>
                </div>

                <div id="service-list">
                        <div id="shop">
                            <span style="height:2px">增加商店</span>
                            <hr class="layui-bg-green">
                            <br>
                            <br>
                            <div class="layui-form" >
                                <div class="layui-form-item">
                                        <label class="layui-form-label">店名</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="title" required lay-verify="required" placeholder="请输入店名"
                                                autocomplete="off" class="layui-input" v-model="shop">
                                        </div>
                                </div>
    
                                <div class="layui-form-item">
                                    <label class="layui-form-label">店描述</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="title" required lay-verify="required" placeholder="请输入店描述"
                                            autocomplete="off" class="layui-input" v-model="shopInfo">
                                    </div>
                                </div>
            
                                <div class="layui-form-item">
                                    <label class="layui-form-label">店主id</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="title" required lay-verify="required" placeholder="请输入店主id"
                                            autocomplete="off" class="layui-input" v-model="shopId">
                                    </div>
                                </div>
            
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn" lay-submit  @click="addhop()" >立即提交</button>
                                    </div>
                                </div>
    
                                <label>{{tip}}</label>
    
                            </div>
                            
                        </div>
                    </div>

                </div>

                <div style="    margin: 80px auto;
                width: 1000px;
                height: 600px;">
                    <div id="acct" class="layui-row layui-col-space5  ">
                        <span style="font-size: 20px">账号</span>
                        <hr class="layui-bg-green">
                        <table class="layui-table">
                            <colgroup>
                                <col width="150">
                                <col width="200">
                                <col>
                            </colgroup>
        
                            <thead>
                                <tr>
                                    <th style="width:25%">昵称</th>
                                    <th style="width:25%">账号</th>
                                    <th style="width:25%">账号id</th>
                                    <th style="width:25%">角色</th>
                                </tr>
                            </thead>

                            <tbody v-for="account in accounts">
                                <tr>
                                    <td>{{account.nickName}}</td>
                                    <td>{{account.account}}</td>
                                    <td>{{account.aid}}</td>
                                    <td>{{account.role}}</td>
                                </tr>
        
                            </tbody>
                        </table>
        
        
        
        
                    </div>

                    <br>
                    <br>
                    <br>
                    <br>
                    <br>
                    <br>

                    <div id="shopList" class="layui-row layui-col-space5  ">
                        <span style="font-size: 20px">商店</span>
                        <hr class="layui-bg-green">
                        <table class="layui-table">
                            <colgroup>
                                <col width="150">
                                <col width="200">
                                <col>
                            </colgroup>
        
                            <thead>
                                <tr>
                                    <th style="width:25%">商店id</th>
                                    <th style="width:25%">商店名字</th>
                                    <th style="width:25%">商店描述</th>
                                    <th style="width:25%">商店店主id</th>
                                </tr>
                            </thead>

                            <tbody v-for="shop in shopList">
                                <tr>
                                    <td>{{shop.id}}</td>
                                    <td>{{shop.shop}}</td>
                                    <td>{{shop.shopInfo}}</td>
                                    <td>{{shop.shopId}}</td>
                                </tr>
        
                            </tbody>
                        </table>
        
        
        
        
                    </div>

                    <br>
                    <br>
                    <br>
                    <br>
                    <br>
                    <br>
                </div>

            </div>

        </div>
        
    
        <script src="../js/framework/vue.js"></script>
        <script src="../js/framework/layui.js"></script>
        <script src="../js/framework/jquery-3.2.1.min.js"></script>
        <script src="../js/im_index/commons.js"></script>
        <script src="../js/framework/bootstrap.min.js"></script>
 
 
 
        <script> 

        checkRole(3)
        checkLogin()

        // data loading...
        $(function () {

            url = "http://localhost:8080/user/getAccount";
            $.ajax({
                url: url,
                type: 'get',
                contentType: 'application/json; charset=UTF-8',
                success: function (userList) {
                    acct.accounts = userList.data;
                    //   return userList
                },
                error: function () {
                    console.log("服务器获取失败");
                }
            });


            url = "http://localhost:8080/user/getShop";
            $.ajax({
                url: url,
                type: 'get',
                contentType: 'application/json; charset=UTF-8',
                success: function (userList) {
                    shopList.shopList = userList.data;
                    //   return userList
                },
                error: function () {
                    console.log("服务器获取失败");
                }
            });
        
        });

        var reginfo = new Vue({
            el: '#service-list',
            data: {
                nickname: "",
                account: "",
                password: "",
                role: "",
                tip: ""
            },
            methods: {

                register: function () {
                    console.log(this.nickname)
                    if (reginfo.nickname == "" || reginfo.account == "" || reginfo.password == "" || reginfo.role == "") {
                        reginfo.tip = "请输入完整!";
                        return;
                    }

                    if(isNaN(reginfo.role)) {
                        reginfo.tip = "角色应该为数字!";
                        return
                    }

                    var registerurl = "http://localhost:8080/user/register"
                    $.post(registerurl, {
                        "nickName" : this.nickname,      
                        "account" : this.account,      
                        "password" : this.password,      
                        "role" : this.role 
                    }, function (result) {
                        if(result.code == 0) {
                            reginfo.tip = "注册成功";
			                window.location.href = "admin.html";
                            return;
                        }
                        reginfo.tip = result.msg;	
                    });

                }
            }
        });

        var shop = new Vue({
            el: '#shop',
            data: {
                shop: "",
                shopInfo: "",
                shopId: "",
                tip:""
            },
            methods: {

                addhop: function () {

                    if (shop.shop == "" || shop.shopInfo == "" || shop.shopId == "") {
                        shop.tip = "请输入完整!";
                        return;
                    }

                    if(isNaN(this.shopId)) {
                        shop.tip = "店主id应该为数字!";
                        return
                    }

                    var addshop = "http://localhost:8080/user/shop"
                    $.post(addshop, {
                        "shop" : this.shop,      
                        "shopInfo" : this.shopInfo,      
                        "shopId" : this.shopId
                    }, function (result) {
                        console.log(result)
                        if(result.code == 0) {
                            shop.tip = "增加成功";
			                window.location.href = "admin.html";
                            return;
                        }
                        shop.tip = result.msg;
                        
                    });

                }
            }
        });


        // 账号
        var acct = new Vue({
            el: '#acct',
            data: {
                accounts:[]
            },
            methods: {

            }
        });

        // 商店
        var shopList = new Vue({
            el: '#shopList',
            data: {
                shopList:[]
            },
            methods: {

            }
        });

        </script>

    </body>
</html>